package util;


import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.HashMap;
import java.util.Map;

public class Coding {
    public static void main(String[] args) {
        // 父工程
        String basePath = System.getProperty("user.dir");
        // 表名
        String table = "prescription";
        // 子项目
        String project = "caiwu";
        // 单独设置模块路径
        String entity_path = basePath + "/entity/src/main/java/com/neuedu/entity";
        String mapper_path = basePath + "/" + project + "/src/main/java/com/neuedu/mapper";
        String xml_path = basePath + "/" + project + "/src/main/resources/com/neuedu/mapper";
        String service_path = basePath + "/" + project + "/src/main/java/com/neuedu/service";
        String service_impl_path = basePath + "/" + project + "/src/main/java/com/neuedu/service/impl";
        String controller_path = basePath + "/" + project + "/src/main/java/com/neuedu/controller";
        String url = "jdbc:mysql://192.168.116.105:3306/db";
        FastAutoGenerator.create(url, "root", "123")
                .globalConfig(i -> {
                    i.author("LiYang")
                        .disableOpenDir();
                }).packageConfig(i -> {
                    Map<OutputFile, String> pathInfo = new HashMap<>();
                    pathInfo.put(OutputFile.entity, entity_path);
                    pathInfo.put(OutputFile.mapper, mapper_path);
                    pathInfo.put(OutputFile.xml, xml_path);
                    pathInfo.put(OutputFile.service, service_path);
                    pathInfo.put(OutputFile.serviceImpl, service_impl_path);
                    pathInfo.put(OutputFile.controller, controller_path);
                    i.parent("com.neuedu")
                            // 自定义路径
                            .pathInfo(pathInfo);
                }).strategyConfig(i -> {
                    i.addInclude(table)
                            .entityBuilder()
                            .enableLombok()
                            .naming(NamingStrategy.underline_to_camel)
                            .columnNaming(NamingStrategy.underline_to_camel)
                            .controllerBuilder()
                            .enableRestStyle()
                            .serviceBuilder()
                            .formatServiceFileName("%sService");
                }).templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
